package com 
{
	import data.*;
	import flash.utils.Dictionary;
	
	/**
	 * A logical representation of a single building structure within the city.
	 * Some buildings are harvest buildings that can gather resources, others
	 * may have special properties.
	 * 
	 * A building will also have special description text and a cost to
	 * construct. These would be accessible through static methods elsewhere.
	 * 
	 * @author Jason Won
	 */
	public class GCCityBuilding 
	{
		// The unique identifier for this building
		private var _buildingId:uint;
		
		// The unique identifier for the type of resource that this
		// building can gather, if any
		private var _resource:uint;
		
		/*
		 * Identify whether this building is a harvest building or some other
		 * special structure.
		 */
		private var _type:uint;
		
		/*
		 * The number of workers who are assigned to this building, is zero if
		 * no one is working here or if it is a special building that does not
		 * accept workers.
		 */
		public var _numWorkers:int;
		
		/*
		 * Function representing the gathering rate of resources at this
		 * particular building
		 */
		private var rate:int;			//TODO what to change this to hard code calculated value
		
		/**
		 * Construct a new building. Should be called on game startup to load up
		 * buildings from previous play session OR in-game if a player explicitly
		 * chooses to build something new.
		 * 
		 * @param	type
		 * @param	numWorkers
		 * @param	rate
		 */
		public function GCCityBuilding(buildingId:int, numWorkers:int, rate:int=0)
		{
			this._buildingId = buildingId;
			this._numWorkers = numWorkers;
			this._type = GCBuildingData.getBuildingTypeFromId(buildingId);
			this.rate = rate;
		}
		
		/**
		 * Get a clone of this building
		 * 
		 * @return
		 */
		public function getClone():GCCityBuilding
		{
			return new GCCityBuilding(this._buildingId, this._numWorkers);
		}
		
		/** Get Functions **/
		public function get buildingId():uint
		{
			return _buildingId;
		}
		
		public function get numWorkers():int
		{
			return _numWorkers;
		}
		
		public function getType():uint
		{
			return _type;
		}
		
		public function getName():String
		{
			return GCBuildingData.getNameFromId(this._buildingId);
		}
		
		// TODO: Fill in with a better rate than linear
		public function getRate():int
		{
			return _numWorkers;//rate; 
		}
		
		public function getHarvestableResource():uint
		{
			return GCBuildingData.getResourceFromId(_buildingId);
		}
		
		/** Set Functions **/
		public function set numWorkers(value:int):void
		{
			_numWorkers = value;
		}
		
		/**
		 * Predicts the new rate at which resources are gathered depending on the
		 * new number of workers.
		 * 
		 * @param	numWorkers
		 */
		public function predictNewRate(numWorkers:uint):uint
		{
			return numWorkers;
		}
		
		public static function getGoldCost(id:uint):uint
		{
			return GCBuildingData.getGoldCostFromId(id);
		}
		
		public static function getResourceCost(id:uint):Dictionary
		{
			return GCBuildingData.getResourceCostFromId(id);
		}
	}

}